﻿Imports _1065144_1065164.DataProvider
Imports System.Data.SqlClient
Public Class TaiKhoanNguoiDungDAO
    Public Shared Function GetAll() As DataTable
        Dim listTKNguoiDung As New DataTable()
        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "ketTAIKHOANNGUOIDUNGvaLOAITAIKHOAN"
        cmd.Connection = cn

        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
        da.Fill(listTKNguoiDung)


        Return listTKNguoiDung


    End Function
    Public Shared Sub Insert(ByVal sqlparameters As SqlParameter())
        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "themtaikhoan"
        cmd.Parameters.AddRange(sqlparameters)
        cmd.Connection = cn
        cn.Open()
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
    '' lay ID tai khoan
    Public Shared Function GetByID(ByVal para As SqlParameter) As List(Of TaiKhoanNguoiDungDTO)
        Dim listTaiKhoan As New List(Of TaiKhoanNguoiDungDTO)
        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "TTTaiKhoan"
        cmd.Connection = cn
        cmd.Parameters.Add(para)
        cn.Open()
        Dim rd As SqlDataReader = cmd.ExecuteReader()
        While rd.Read()
            Dim taikhoan As TaiKhoanNguoiDungDTO = New TaiKhoanNguoiDungDTO()

            taikhoan.strTenTaiKhoan = rd.GetString(0)
            taikhoan.strMatKhau = rd.GetString(1)
            taikhoan.iMaLoaiTaiKhoan = rd.GetInt32(2)
            taikhoan.iMaTaiKhoan = rd.GetInt32(3)

            listTaiKhoan.Add(taikhoan)
        End While
        cn.Close()

        Return listTaiKhoan
    End Function
    Public Shared Sub Update(ByVal sqlparameters As SqlParameter())
        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "SuaThongTinTaiKhoan"
        cmd.Connection = cn
        cmd.Parameters.AddRange(sqlparameters)
        cn.Open()
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Shared Sub Delete(ByVal sqlparameters As SqlParameter)
        Dim cn As SqlConnection = New SqlConnection(_strConnectionString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "XoaTaiKhoan"
        cmd.Connection = cn
        cmd.Parameters.Add(sqlparameters)
        cn.Open()
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
End Class
